<template>
  <div class="profile-container">
    <h1>个人信息</h1>
    <el-form :model="userProfile" :rules="rules" ref="profileForm" label-width="100px" class="profile-form">
      <el-form-item label="ID">
        <el-input v-model="userProfile.id" disabled></el-input>
      </el-form-item>
      <el-form-item label="用户名">
        <el-input v-model="userProfile.username" disabled></el-input>
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="userProfile.name"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-select v-model="userProfile.gender" placeholder="请选择性别">
          <el-option label="男" value="male"></el-option>
          <el-option label="女" value="female"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="userProfile.phone"></el-input>
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input v-model="userProfile.address"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveProfile">修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'AdminProfile',
  data() {
    return {
      userProfile: {
        id: '123456',
        username: 'user123',
        name: '张三',
        gender: 'male',
        phone: '12345678901',
        address: '北京市海淀区'
      },
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        gender: [
          { required: true, message: '请选择性别', trigger: 'change' }
        ],
        phone: [
          { required: true, message: '请输入联系电话', trigger: 'blur' },
          { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '请输入地址', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    saveProfile() {
      this.$refs.profileForm.validate((valid) => {
        if (valid) {
          // 处理保存个人信息逻辑
          alert('个人信息已保存!');
        } else {
          this.$message.error('请正确填写信息');
          return false;
        }
      });
    }
  }
};
</script>

<style scoped>
.profile-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 80vh;
}

.profile-form {
  width: 400px;
}
</style>
